package io.gatling.extensions.mongodb.check

import io.gatling.commons.validation._
import io.gatling.core.check.FindExtractor
import org.mongodb.scala.result._

object MongoExtractors {

  private[check] val matchedCountExtractor: FindExtractor[UpdateResult, Long] = new FindExtractor[UpdateResult, Long](
    "matchedCount",
    prepared => Some(prepared.getMatchedCount).success
  )

  private[check] val modifiedCountExtractor: FindExtractor[UpdateResult, Long] = new FindExtractor[UpdateResult, Long](
    "modifiedCount",
    prepared => Some(prepared.getModifiedCount).success
  )

  private[check] val wasAcknowledgedOneExtractor: FindExtractor[InsertOneResult, Boolean] = new FindExtractor[InsertOneResult, Boolean](
    "wasAcknowledgedOne",
    prepared => Some(prepared.wasAcknowledged()).success
  )

  private[check] val wasAcknowledgedManyExtractor: FindExtractor[InsertManyResult, Boolean] = new FindExtractor[InsertManyResult, Boolean](
    "wasAcknowledgedManyExtractor",
    prepared => Some(prepared.wasAcknowledged()).success
  )

  private[check] val deletedCountExtractor: FindExtractor[DeleteResult, Long] = new FindExtractor[DeleteResult, Long](
    "deletedCount",
    prepared => Some(prepared.getDeletedCount).success
  )
}
